import { FriendInfo } from "../../../model/FriendInfo";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { Language } from "../../../../../extend/language/Language";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ObjCreate } from "../../common/ObjCreate";
import { TilePanel } from "../../equipment/TilePanel";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { FriendIntimateCellRenderer } from "../FriendIntimateCellRenderer";
import { FriendCellRenderer2 } from "../FriendCellRenderer2";
import { GScrollPane } from "../../../../../com/mui/controls/GScrollPane";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class FriendInimateList
    
    export  class FriendInimateList /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            this.initEventListener();
            return;
        }

        /* internal  */initEventListener(): void
        {
            this._btnExpandFriend.addEventListener(flash.events.MouseEvent.CLICK, this.clickExpandHandler);
            this._btnExpandInimate.addEventListener(flash.events.MouseEvent.CLICK, this.clickExpandHandler);
            this._btnShrinFriend.addEventListener(flash.events.MouseEvent.CLICK, this.clickExpandHandler);
            this._btnShrinInimate.addEventListener(flash.events.MouseEvent.CLICK, this.clickExpandHandler);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }

        public updateFriendView(arg1: Vector.<FriendInfo>, arg2: Boolean=false): void
        {
            var loc1=this.getProviderAndOnlineNum(arg1);
            var loc2=arg1.length;
            this._friendHeight = loc2 * this.CellHeight;
            this._friendList.height = this.getFriendListShowingHeight();
            this._friendList.width = 193;
            this._friendList.dataProvider = DataProvider(loc1[0]);
            this._friendList.drawNow();
            this._friendList.validateNow();
            this._txtTitleFriend.htmlText = "<font color=\'#F1FFB1\'>" + Language.getString(40369) + "(" + int(loc1[1]).toString() + "/" + loc2.toString() + ")</font>";
            this.resetPlaces();
            return;
        }

        public updateInimateView(arg1: Vector.<FriendInfo>, arg2: Boolean=false): void
        {
            var loc1=this.getProviderAndOnlineNum(arg1);
            var loc2=arg1.length;
            this._inimateHeight = loc2 * this.CellHeight;
            this._inimateList.height = this.getInimateListShowingHeight();
            this._inimateList.width = 193;
            this._inimateList.dataProvider = DataProvider(loc1[0]);
            this._inimateList.drawNow();
            this._inimateList.validateNow();
            this._txtTitleInimate.htmlText = "<font color=\'#F1FFB1\'>" + Language.getString(40408) + "(" + int(loc1[1]).toString() + "/" + loc2.toString() + ")</font>";
            this.resetPlaces();
            return;
        }

        /* internal  */getProviderAndOnlineNum(arg1: Vector.<FriendInfo>, arg2: Boolean=false): Array<any>
        {
            var loc4=null;
            var loc1=[];
            var loc2=new DataProvider();
            var loc3=0;
            var loc5=0;
            var loc6=arg1;
            for(loc4 of loc6) 
            {
                if (arg2 && loc4.friendPlayerInfo.online || !arg2) 
                {
                    loc2.addItem(loc4);
                }
                if (!loc4.friendPlayerInfo.online) 
                {
                    continue;
                }
                ++loc3;
            }
            loc1.push(loc2, loc3);
            return loc1;
        }

        /* internal  */resetPlaces(): void
        {
            var onTimeOut: Function;

            var loc1;
            onTimeOut = null;
            onTimeOut = (): void
            {
                _inimateList.y = _spInimate.y + _spInimate.height + 2;
                _spFriend.y = _inimateList.y + _inimateList.height + 2;
                _friendList.y = _spFriend.y + _spFriend.height + 2;
                _scrollPane.update();
                return;
            }
            this._inimateList.y = this._spInimate.y + this._spInimate.height + 2;
            this._spFriend.y = this._inimateList.y + this._inimateList.height + 2;
            this._friendList.y = this._spFriend.y + this._spFriend.height + 2;
            flash.utils.setTimeout(onTimeOut, 120);
            return;
        }

        /* internal  */clickExpandHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            var loc2=loc1;
            switch (loc2) 
            {
                case this._btnExpandFriend:
                {
                    this.expandFriend();
                    break;
                }
                case this._btnExpandInimate:
                {
                    this.expandInimate();
                    break;
                }
                case this._btnShrinFriend:
                {
                    this.shrinFriend();
                    break;
                }
                case this._btnShrinInimate:
                {
                    this.shrinInimate();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var onTimeOut: Function;

            var loc1;
            onTimeOut = null;
            e = arg1;
            onTimeOut = (): void
            {
                _scrollPane.update();
                return;
            }
            flash.utils.setTimeout(onTimeOut, 300);
            return;
        }

        public expandFriend(): void
        {
            this._btnExpandFriend.visible = false;
            this._btnShrinFriend.visible = true;
            this._friendList.visible = true;
            this._friendList.height = this.getFriendListShowingHeight();
            this._friendList.width = 193;
            this.resetPlaces();
            return;
        }

        public shrinFriend(): void
        {
            this._btnExpandFriend.visible = true;
            this._btnShrinFriend.visible = false;
            this._friendList.visible = false;
            this._friendList.height = this.getFriendListShowingHeight();
            this._friendList.width = 193;
            this.resetPlaces();
            return;
        }

        public expandInimate(): void
        {
            this._btnExpandInimate.visible = false;
            this._btnShrinInimate.visible = true;
            this._inimateList.visible = true;
            this._inimateList.height = this.getInimateListShowingHeight();
            this._inimateList.width = 193;
            this.resetPlaces();
            return;
        }

        public shrinInimate(): void
        {
            this._btnExpandInimate.visible = true;
            this._btnShrinInimate.visible = false;
            this._inimateList.visible = false;
            this._inimateList.height = this.getInimateListShowingHeight();
            this._inimateList.width = 193;
            this.resetPlaces();
            return;
        }

        /* internal  */getFriendListShowingHeight(): int
        {
            if (this._friendList.visible) 
            {
                return this._friendHeight + 2;
            }
            return 1;
        }

        /* internal  */getInimateListShowingHeight(): int
        {
            if (this._inimateList.visible) 
            {
                return this._inimateHeight + 2;
            }
            return 1;
        }

        /* internal  */initView(): void
        {
            var loc1=new Object /* flash.display.Sprite */();
            this._spInimate = new Object /* flash.display.Sprite */();
            this._btnExpandInimate = ObjCreate.createGButton("", 0, 0, 20, 20, this._spInimate, "SupBtn2");
            this._btnShrinInimate = ObjCreate.createGButton("", 0, 0, 20, 20, this._spInimate, "SubBtn2");
            this._txtTitleInimate = ObjCreate.createGTextField("", 20, 2, 120, 20, this._spInimate);
            loc1.addChild(this._spInimate);
            this._inimateList = new TilePanel();
            this._inimateList.x = 4;
            this._inimateList.width = 190;
            this._inimateList.height = 1;
            this._inimateList.columnWidth = 189;
            this._inimateList.rowHeight = 38;
            this._inimateList.verticalScrollPolicy = ScrollPolicy.OFF;
            this._inimateList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._inimateList.setStyle("cellRenderer", FriendIntimateCellRenderer);
            loc1.addChild(this._inimateList);
            this._spFriend = new Object /* flash.display.Sprite */();
            this._btnExpandFriend = ObjCreate.createGButton("", 0, 0, 20, 20, this._spFriend, "SupBtn2");
            this._btnShrinFriend = ObjCreate.createGButton("", 0, 0, 20, 20, this._spFriend, "SubBtn2");
            this._txtTitleFriend = ObjCreate.createGTextField("", 20, 2, 120, 20, this._spFriend);
            loc1.addChild(this._spFriend);
            this._friendList = new TilePanel();
            this._friendList.x = 4;
            this._friendList.width = 190;
            this._friendList.height = 1;
            this._friendList.columnWidth = 189;
            this._friendList.rowHeight = 38;
            this._friendList.verticalScrollPolicy = ScrollPolicy.OFF;
            this._friendList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._friendList.setStyle("cellRenderer", FriendCellRenderer2);
            loc1.addChild(this._friendList);
            this._scrollPane = new GScrollPane();
            this._scrollPane.x = 0;
            this._scrollPane.y = 20;
            this._scrollPane.setSize(200, 255);
            this._scrollPane.source = loc1;
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.setScrollBarSize(19);
            this._scrollPane.update();
            addChild(this._scrollPane);
            this.expandFriend();
            this.expandInimate();
            return;
        }

        /* internal */ /* const */CellHeight: int=38;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_friendList: TilePanel;

        /* internal */ /* var */_inimateList: TilePanel;

        /* internal */ /* var */_btnExpandFriend: GButton;

        /* internal */ /* var */_btnShrinFriend: GButton;

        /* internal */ /* var */_spFriend: Object /* flash.display.Sprite */;

        /* internal */ /* var */_txtTitleFriend: GTextFiled;

        /* internal */ /* var */_btnExpandInimate: GButton;

        /* internal */ /* var */_btnShrinInimate: GButton;

        /* internal */ /* var */_spInimate: Object /* flash.display.Sprite */;

        /* internal */ /* var */_txtTitleInimate: GTextFiled;

        /* internal */ /* var */_friendHeight: int=1;

        /* internal */ /* var */_inimateHeight: int=1;
    }
